package sit.engreal.leetcode.problems100;

import static org.junit.jupiter.api.Assertions.*;

/**
 * <a href="https://leetcode.cn/problems/palindrome-number/"> 9. 回文数 </a>
 */
public class LeetCode9 {

    public static void main(String[] args) {
        class Solution {
            public boolean isPalindrome(int x) {
                if (x < 0) {
                    return false;
                }
                if (x < 10) {
                    return true;
                }

                int y = 0;
                int z = x;
                while (z > 0) {
                    y = (y * 10) + (z % 10);
                    z /= 10;
                }
                return x == y;
            }
        }

        final Solution solution = new Solution();

        assertTrue(solution.isPalindrome(121));

        assertFalse(solution.isPalindrome(-121));
        assertFalse(solution.isPalindrome(10));
    }
}
